// pages/personalCenter/recruitForm/form/items/items.js
var saveTextField = require('./module/saveTextField.js');
var saveTextFields = require('./module/saveTextFields.js');
var saveSelect = require('./module/saveSelect.js');
var saveSelects = require('./module/saveSelects.js');
var saveNumber = require('./module/saveNumber.js');
var saveFiles = require('./module/saveFiles');
var saveHeader = require('./module/saveHeader.js');
var app = getApp();
//用来临时储存一个要放入user_form中的对象
var temporalItem = {};
Page({
    /**
     * 自定义函数
     */
    //每次打开页面检查是否是新建项目，要新建的是哪个项目
    whichItem: function() {
        this.setData({
            item: app.globalData.user_form[0].new_item
        })
        //编辑项目
        if (app.globalData.user_form[0].edit == true) {
            //当是编辑修改一个旧的项目时设置页面标题并且给输入框赋值
            if (app.globalData.user_form[0].new_item == 'text_field') {
                wx.setNavigationBarTitle({
                    title: '修改单行文本'
                });
                this.setData({
                    value_i_input_textField_name_edit: app.globalData.user_form[app.globalData.user_form[0].edit_num].item_name
                });
                this.setData({
                    value_i_input_textField_notice_edit: app.globalData.user_form[app.globalData.user_form[0].edit_num].item_des
                })
                this.setData({
                    value_i_switch_textField: app.globalData.user_form[app.globalData.user_form[0].edit_num].item_nec
                })
                //重新赋值
                temporalItem.name = app.globalData.user_form[app.globalData.user_form[0].edit_num].item_name;
                temporalItem.notice = app.globalData.user_form[app.globalData.user_form[0].edit_num].item_des;
                temporalItem.switchValue = app.globalData.user_form[app.globalData.user_form[0].edit_num].item_nec;
            } else if (app.globalData.user_form[0].new_item == 'text_fields') {
                wx.setNavigationBarTitle({
                    title: '修改多行文本'
                });
                this.setData({
                    value_i_input_textFields_name_edit: app.globalData.user_form[app.globalData.user_form[0].edit_num].item_name
                });
                this.setData({
                    value_i_input_textFields_notice_edit: app.globalData.user_form[app.globalData.user_form[0].edit_num].item_des
                })
                this.setData({
                    value_i_switch_textFields: app.globalData.user_form[app.globalData.user_form[0].edit_num].item_nec
                })
                //重新赋值
                temporalItem.name = app.globalData.user_form[app.globalData.user_form[0].edit_num].item_name;
                temporalItem.switchValue = app.globalData.user_form[app.globalData.user_form[0].edit_num].item_nec;
                temporalItem.notice = app.globalData.user_form[app.globalData.user_form[0].edit_num].item_des;
            } else if (app.globalData.user_form[0].new_item == 'select') {
                wx.setNavigationBarTitle({
                    title: '修改单项选择'
                });
                this.setData({
                    value_i_input_select_name_edit: app.globalData.user_form[app.globalData.user_form[0].edit_num].item_name
                });
                this.setData({
                    value_i_input_select_notice_edit: app.globalData.user_form[app.globalData.user_form[0].edit_num].item_des
                })
                this.setData({
                    value_i_switch_select: app.globalData.user_form[app.globalData.user_form[0].edit_num].item_nec
                })
                this.setData({
                    select_num: app.globalData.user_form[app.globalData.user_form[0].edit_num].options
                })
                //重新赋值
                temporalItem.name = app.globalData.user_form[app.globalData.user_form[0].edit_num].item_name;
                temporalItem.notice = app.globalData.user_form[app.globalData.user_form[0].edit_num].item_des;
                temporalItem.switchValue = app.globalData.user_form[app.globalData.user_form[0].edit_num].item_nec;
            } else if (app.globalData.user_form[0].new_item == 'selects') {
                wx.setNavigationBarTitle({
                    title: '修改多项选择'
                });
                this.setData({
                    value_i_input_selects_name_edit: app.globalData.user_form[app.globalData.user_form[0].edit_num].item_name
                });
                this.setData({
                    value_i_input_selects_notice_edit: app.globalData.user_form[app.globalData.user_form[0].edit_num].item_des
                })
                this.setData({
                    value_i_switch_selects: app.globalData.user_form[app.globalData.user_form[0].edit_num].item_nec
                })
                this.setData({
                    selects_num: app.globalData.user_form[app.globalData.user_form[0].edit_num].options
                })
                //重新赋值
                temporalItem.name = app.globalData.user_form[app.globalData.user_form[0].edit_num].item_name;
                temporalItem.notice = app.globalData.user_form[app.globalData.user_form[0].edit_num].item_des;
                temporalItem.switchValue = app.globalData.user_form[app.globalData.user_form[0].edit_num].item_nec;
            } else if (app.globalData.user_form[0].new_item == 'number') {
                wx.setNavigationBarTitle({
                    title: '修改手机号/QQ号/微信号输入框'
                });
                this.setData({
                    value_i_switch_number: false
                })
            } else if (app.globalData.user_form[0].new_item == 'files') {
                wx.setNavigationBarTitle({
                    title: '修改附件'
                });
                this.setData({
                    value_i_input_files_name_edit: app.globalData.user_form[app.globalData.user_form[0].edit_num].item_name
                });
                this.setData({
                    value_i_input_files_notice_edit: app.globalData.user_form[app.globalData.user_form[0].edit_num].item_des
                })
                this.setData({
                    value_i_switch_files: app.globalData.user_form[app.globalData.user_form[0].edit_num].item_nec
                })
                //重新赋值
                temporalItem.name = app.globalData.user_form[app.globalData.user_form[0].edit_num].item_name;
                temporalItem.switchValue = app.globalData.user_form[app.globalData.user_form[0].edit_num].item_nec;
                temporalItem.notice = app.globalData.user_form[app.globalData.user_form[0].edit_num].item_des;
            } else if (app.globalData.user_form[0].new_item == 'header') {
                wx.setNavigationBarTitle({
                    title: '修改表头信息'
                });
                this.setData({
                    value_i_input_form_name_edit: app.globalData.user_form[app.globalData.user_form[0].edit_num].form_name
                });
                this.setData({
                    value_i_input_form_des_edit: app.globalData.user_form[app.globalData.user_form[0].edit_num].form_des
                })
                //重新赋值
                temporalItem.name = app.globalData.user_form[app.globalData.user_form[0].edit_num].form_name;
                temporalItem.notice = app.globalData.user_form[app.globalData.user_form[0].edit_num].form_des;
            }
        }
    },


    /**
     * 页面函数
     */

    /**
     * 表头
     */

    //编辑图片
    new_header_img: function() {},

    //表单名称
    new_form_name_input: function(e) {
        temporalItem.name = e.detail.detail.value;
    },

    //表单描述
    new_form_des_input: function(e) {
        temporalItem.notice = e.detail.detail.value;
    },

    //点击保存
    bind_i_button_header_save: function() {
        saveHeader(temporalItem);
    },

    //点击重置
    bind_i_button_header_reset: function() {
        wx.showModal({
            title: '提示',
            content: '重置功能暂未开放，请手动删除',
            showCancel: false,
            confirmText: '我知道了'
        })
    },

    //点击返回
    bind_i_button_header_cancel: function() {
        //返回上一个页面
        wx.navigateBack({
            url: '../items'
        })
    },

    /**
     * 右侧单行文本
     */

    //是否为必填项
    bind_i_switch_textField_necessary: function() {
        this.setData({
            value_i_switch_textField: !this.data.value_i_switch_textField
        })
        temporalItem.switchValue = this.data.value_i_switch_textField;
    },

    //字段名称
    bind_i_input_textField_name: function(e) {
        temporalItem.name = e.detail.detail.value;
    },

    //字段提示
    bind_i_input_textField_notice: function(e) {
        temporalItem.notice = e.detail.detail.value;
    },

    //点击保存
    bind_i_button_textField_save: function() {
        saveTextField(temporalItem);
    },

    //点击重置
    bind_i_button_textField_reset: function() {
        wx.showModal({
            title: '提示',
            content: '重置功能暂未开放，请手动删除',
            showCancel: false,
            confirmText: '我知道了'
        })
    },

    //点击返回
    bind_i_button_textField_cancel: function() {
        //返回上一个页面
        wx.navigateBack({
            url: '../items'
        })
    },

    /**
     * 右侧多行文本
     */

    //是否为必填项
    bind_i_switch_textFields_necessary: function() {
        this.setData({
            value_i_switch_textFields: !this.data.value_i_switch_textFields
        });
        temporalItem.switchValue = this.data.value_i_switch_textFields;
    },

    //字段名称
    bind_i_input_textFields_name: function(e) {
        temporalItem.name = e.detail.detail.value;
    },

    //字段提示
    bind_i_input_textFields_notice: function(e) {
        temporalItem.notice = e.detail.detail.value;
    },

    //点击保存
    bind_i_button_textFields_save: function() {
        saveTextFields(temporalItem);
    },

    //点击重置
    bind_i_button_textFields_reset: function() {
        wx.showModal({
            title: '提示',
            content: '重置功能暂未开放，请手动删除',
            showCancel: false,
            confirmText: '我知道了'
        })
    },

    //点击返回
    bind_i_button_textFields_cancel: function() {
        //返回上一个页面
        wx.navigateBack({
            url: '../items'
        })
    },

    /**
     * 右侧单选框
     */

    //是否为必填项
    bind_i_switch_select_necessary: function(e) {
        this.setData({
            value_i_switch_select: !this.data.value_i_switch_select
        });
        temporalItem.switchValue = this.data.value_i_switch_select;
    },

    //字段名称
    bind_i_input_select_name: function(e) {
        temporalItem.name = e.detail.detail.value;
    },

    //字段提示
    bind_i_input_select_notice: function(e) {
        temporalItem.notice = e.detail.detail.value;
    },

    //新建一项
    bind_i_button_select_new: function() {
        this.data.select_num.push('');
        this.setData({
            select_num: this.data.select_num
        });
    },

    //每一项的名称
    bind_i_input_select_option_name: function(e) {
        this.data.select_num.splice(e.currentTarget.id, 1, e.detail.detail.value);
        this.setData({
            select_num: this.data.select_num
        });
    },

    //点击保存
    bind_i_button_select_save: function() {
        saveSelect(temporalItem, this.data.select_num);
    },

    //点击重置
    bind_i_button_select_reset: function() {
        wx.showModal({
            title: '提示',
            content: '重置功能暂未开放，请手动删除',
            showCancel: false,
            confirmText: '我知道了'
        })
    },

    //点击返回
    bind_i_button_select_cancel: function() {
        //返回上一个页面
        wx.navigateBack({
            url: '../items'
        })
    },

    /**
     * 右侧多选框
     */

    //是否为必填项
    bind_i_switch_selects_necessary: function(e) {
        this.setData({
            value_i_switch_selects: !this.data.value_i_switch_selects
        });
        temporalItem.switchValue = this.data.value_i_switch_selects;
    },

    //字段名称
    bind_i_input_selects_name: function(e) {
        temporalItem.name = e.detail.detail.value;
    },

    //字段提示
    bind_i_input_selects_notice: function(e) {
        temporalItem.notice = e.detail.detail.value;
    },

    //新建一项
    bind_i_button_selects_new: function() {
        this.data.selects_num.push('');
        this.setData({
            selects_num: this.data.selects_num
        });
    },

    //每一项的名称
    bind_i_input_selects_option_name: function(e) {
        this.data.selects_num.splice(e.currentTarget.id, 1, e.detail.detail.value);
        this.setData({
            selects_num: this.data.selects_num
        });
    },

    //点击保存
    bind_i_button_selects_save: function() {
        saveSelects(temporalItem, this.data.selects_num);
    },

    /**
     * 右侧手机号/QQ号/微信号
     */

    //是否为必填项
    bind_i_switch_number_necessary: function(e) {
        this.setData({
            value_i_switch_number: !this.data.value_i_switch_number
        })
    },

    //选择的项目
    bind_i_radio_number: function(e) {
        this.setData({
            current_i_radio_number: e.detail.value
        });
    },

    //点击保存
    bind_i_button_number_save: function() {
        saveNumber(this.data.current_i_radio_number, this.data.value_i_switch_number);
    },

    //点击重置
    bind_i_button_number_reset: function() {
        wx.showModal({
            title: '提示',
            content: '重置功能暂未开放，请手动删除',
            showCancel: false,
            confirmText: '我知道了'
        })
    },

    //点击返回
    bind_i_button_number_cancel: function() {
        //返回上一个页面
        wx.navigateBack({
            url: '../items'
        })
    },


    //点击重置
    bind_i_button_selects_reset: function() {
        wx.showModal({
            title: '提示',
            content: '重置功能暂未开放，请手动删除',
            showCancel: false,
            confirmText: '我知道了'
        })
    },

    //点击返回
    bind_i_button_selects_cancel: function() {
        //返回上一个页面
        wx.navigateBack({
            url: '../items'
        })
    },

    /**
     * 右侧附件
     */

    //是否为必填项
    bind_i_switch_files_necessary: function() {
        this.setData({
            value_i_switch_files: !this.data.value_i_switch_files
        })
        temporalItem.switchValue = this.data.value_i_switch_files;
    },

    //字段名称
    bind_i_input_files_name: function(e) {
        temporalItem.name = e.detail.detail.value;
    },

    //字段提示
    bind_i_input_files_notice: function(e) {
        temporalItem.notice = e.detail.detail.value;
    },

    //点击保存
    bind_i_button_files_save: function() {
        saveFiles(temporalItem);
    },

    //点击重置
    bind_i_button_files_reset: function() {
        wx.showModal({
            title: '提示',
            content: '重置功能暂未开放，请手动删除',
            showCancel: false,
            confirmText: '我知道了'
        })
    },

    //点击返回
    bind_i_button_files_cancel: function() {
        //返回上一个页面
        wx.navigateBack({
            url: '../items'
        })
    },



    /**
     * 页面的初始数据
     */
    data: {
        //初始选框数量
        select_num: [],
        selects_num: [],

        //手机号/QQ号/微信号选择
        number_items: [
            '手机号',
            'QQ号',
            '微信号',
            '电子邮件'
        ]
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function(options) {},

    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady: function() {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow: function() {
        wx.hideShareMenu({});
        //清空临时变量
        temporalItem = {};
        //每次打开页面检查是否是新建项目，要新建的是哪个项目
        this.whichItem();
    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide: function() {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload: function() {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh: function() {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom: function() {

    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage: function() {

    }
})